package com.itheima.demo02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test03 {
    public static void main(String[] args) {
        //随机抽取学生姓名
        //要求：抽取男生的概率为70%
        //抽取女生的概率为30%

        //思路：定义一个集合记录概率
        ArrayList<Integer> list = new ArrayList<>();

        Collections.addAll(list, 1, 1, 1, 1, 1, 1, 1);//添加7个 1 表示 男生的概率
        Collections.addAll(list, 0, 0, 0);//添加3个 0 表示女生的概率

        //生成随机概率
        Random random = new Random();

        int percentage = random.nextInt(list.size());
        int number = list.get(percentage);

        //创建男生集合
        ArrayList<String> boyList = new ArrayList<>();
        Collections.addAll(boyList,"张三","李四","王五","沄轩","帝宏","成杨","宏均","昌淦","宏鸿","壬庚","诚蔚","永章","永齐","宇浛","云泫","易智");

        //创建女生集合
        ArrayList<String> girlList = new ArrayList<>();
        Collections.addAll(girlList,"梦琪","忆柳","之桃","曼文","沛菡","初夏","元香","尔岚","问兰","慕青");

        //判断是 1 还是 0
        if (number == 1){//1 在男生集合里面抽取
            int boyIndex= random.nextInt(boyList.size());
            String name = boyList.get(boyIndex);
            System.out.println(name);
        }else {//0 在女生集合里面抽取
            int girlIndex = random.nextInt(girlList.size());
            String name = girlList.get(girlIndex);
            System.out.println(name);
        }


    }
}
